namespace Hont
{
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.Networking;

    public class WebAsync : MonoBehaviour
    {
        static WebAsync sInternalInstance;

        static WebAsync InternalInstance
        {
            get
            {
                if (!sInternalInstance)
                {
                    sInternalInstance = new GameObject("[WebAsync]").AddComponent<WebAsync>();
                    DontDestroyOnLoad(sInternalInstance.gameObject);
                }

                return sInternalInstance;
            }
        }

        public static UnityWebRequestWrap From(UnityWebRequest request)
        {
            return From(request, new WebAsyncRequestContext() {TimeOut = 5});
        }

        public static UnityWebRequestWrap From(UnityWebRequest request, WebAsyncRequestContext context)
        {
            return new UnityWebRequestWrap(InternalInstance, context, request);
        }
    }
}